﻿/*
This file is part of Ingo Karstein's SharePoint 2010 Workflow Demo project

**Do not remove this comment**

Please see the project homepage at CodePlex:
  http://spworkflowdemo.codeplex.com/

Please see my blog:
  http://ikarstein.wordpress.com

Licence: GPLv2
    SharePoint 2010 Workflow Demo
    Copyright (C) 2011  Ingo Karstein, ikarstein@hotmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Diagnostics;

namespace ik.SharePoint2010.Workflow.Workflow_2
{
    public sealed partial class Workflow_2 : SequentialWorkflowActivity
    {
        public Workflow_2()
        {
            InitializeComponent();
        }

        public Guid workflowId = default(System.Guid);
        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

        public Workflow2Data WorkflowDataAssociation
        {
            get
            {
                return (Workflow2Data)GetValue(WorkflowDataAssociationProperty);
            }
            set
            {
                SetValue(WorkflowDataAssociationProperty, value);
            }
        }

        // Using a DependencyProperty as the backing store for WorkflowData.  
        //   This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WorkflowDataAssociationProperty =
            DependencyProperty.Register("WorkflowDataAssociation", typeof(Workflow2Data), typeof(Workflow_2));



        public Workflow2Data WorkflowDataInitiation
        {
            get
            {
                return (Workflow2Data)GetValue(WorkflowDataInitiationProperty);
            }
            set
            {
                SetValue(WorkflowDataInitiationProperty, value);
            }
        }

        // Using a DependencyProperty as the backing store for WorkflowDataInitiation.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WorkflowDataInitiationProperty =
            DependencyProperty.Register("WorkflowDataInitiation", typeof(Workflow2Data), typeof(Workflow_2));



        private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
        {
            using( StringReader stringReader = new StringReader(workflowProperties.AssociationData) )
            {
                using( XmlReader reader = XmlReader.Create(stringReader) )
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Workflow2Data));
                    WorkflowDataAssociation = (Workflow2Data)serializer.Deserialize(reader);
                }
            }

            using( StringReader stringReader = new StringReader(workflowProperties.InitiationData) )
            {
                using( XmlReader reader = XmlReader.Create(stringReader) )
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Workflow2Data));
                    WorkflowDataInitiation = (Workflow2Data)serializer.Deserialize(reader);
                }
            }
        }


    }
}
